//-----------------------------------------------------------------------------------
// Lightbox class
//-----------------------------------------------------------------------------------
function Lightbox(configurationUrl)
{
    var config              = null;
    var configurationUrl    = configurationUrl;
        
    //-------------------------------------------------------------------------------
    // Gets the configuration object describing the set of images
    //-------------------------------------------------------------------------------
    function getConfig() 
    {
        if (null == configurationUrl || 
            typeof configurationUrl != "string")
            throw "Invalid configuration URL. Expected type String. " + 
            "Actual type: " + typeof configurationUrl;
        
        return (null == config) ?  
            config = Configuration.load(configurationUrl) : 
            config;
    }
    
    //-------------------------------------------------------------------------------
    // Returns the set of images being displayed
    //-------------------------------------------------------------------------------
    function getImages() 
    {     
        return getConfig();
    }
    
    //-------------------------------------------------------------------------------
    // Opens the lightbox at the specified zero-based index
    //-------------------------------------------------------------------------------
    this.open = function(index, width, height) 
    { 
        if (width == undefined)
        {
            width = 400;
        }
        
        if (height == undefined) 
        {
            height = 300;
        }
        
        Slimbox.open(
            getImages(),
            index,
            {
                loop                : 1,
                overlayOpacity      : 0.75,
                resizeTransition    : Fx.Transitions.Bounce.easeInOut,
                counterText         : "Image {x} of {y}",
                resizeDuration      : 100,
                initialWidth        : width,
		        initialHeight       : height
            }
        );
    }
    
    //-------------------------------------------------------------------------------
    // Applies default effects to a set if image elements
    // @thumbnails: A set of img elements
    //-------------------------------------------------------------------------------
    this.applyThumbnailEffects = function(thumbnails) 
    { 
        if (null == thumbnails)
            throw "ArgumentException. " +
            "Expected thumbnails argument to be a set if images"
        
        var morphDuration   = 200;
        var inTransition    = Fx.Transitions.Bounce.easeIn;
        var outTransition   = Fx.Transitions.Bounce.easeOut;
                
        thumbnails.addEvent(
            "mouseover", 
            function() 
            {
                new Fx.Morph(
	                this,
	                {
	                    duration    : morphDuration, 
	                    transition  : inTransition
	                }
                ).
                cancel().
                start({'opacity' : [0.75]})
            }
        );
        
        thumbnails.addEvent(
            "mouseout", 
            function() 
            {
                new Fx.Morph(
	                this,
	                {
	                    duration    : morphDuration, 
	                    transition  : outTransition
	                }
                ).
                cancel().
                start({'opacity' : [1]})
            }
        );
    }
}